package com.akcome.apollo.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.akcome.apollo.domain.BmpAccountWallet;

/**
 * 账户钱包Repository接口
 *
 * @author wn
 * @version $v: 1.0.0, $time:2017-12-26 08:49:00 Exp $
 */
public interface BmpAccountWalletRepository extends JpaRepository<BmpAccountWallet,Long>,JpaSpecificationExecutor<BmpAccountWallet> {

	int countByAccountIdAndIsEnable(Long accountId,String isEnable);
	
	int countByAccountIdAndCoinType(Long accountId,String coinType);
	
	List<BmpAccountWallet> findByAccountId(Long accountId);
	
	@Query(nativeQuery=true,value="select count(*) from bmp_account_wallet w,bmp_account a ,bmp_user u where w.account_id=a.id and a.user_id=u.id and w.id=?1 and u.id=?2")
	int countByIdAndUserId(Long id,Long userId);
	
	int countByIdAndAccountId(Long id ,Long accountId);
	
	@Transactional
	@Modifying
	@Query(nativeQuery=true,value="update bmp_account_wallet set is_enable='1' where account_id=?2 and id !=?1")
	int disableWallet(Long id ,Long accountId);
}
